Exception-based error handling refers to a programming language construct designed to handle the occurrence of a condition that changes the normal flow of a program during run time. Run time may refer to the operation of a computer program, during code execution (from beginning to end). A condition that changes the normal flow of a program may lead to an error. An exception is then used to signal that an error condition has occurred and the code could not execute normally.
Exception handlers may be used by a programming language to capture information about an exception and to deal with the exception. FIG. 12 depicts psuedocode for an exemplary exception handler, a try/catch construct 1201, which may be placed into program 1200. Try/catch construct 1201 may be comprised of two sections, a ‘try’ block 1210, which may begin with a ‘try’ statement 1212, and a ‘catch’ block 1220, which may begin with a ‘catch’ statement 1222. On execution, the code enters the ‘try’ statement 1212 of the try/catch construct 1201 and executes each statement as if it were part of the regular program. The try/catch construct 1201 may begin with the ‘try’ block 1210, comprising all lines between the ‘try’ statement 1212 and the ‘catch’ statement 1222. Once an error occurs, the ‘try’ block 1210 skips any remaining code in the ‘try’ block 1210 and jumps to the start of the catch block. If all operations in the ‘try’ block 1210 succeed, execution skips the ‘catch’ block 1220 and continues to the first line of code 1230 following the ‘end’ statement 1224. Once an error occurs an exception object may be created and control over the code execution may then transfer to the ‘catch’ block 1220 which may contain an exception handler and end with an ‘end’ statement 1224. The exception object may contain information about the error and the state of the code when the error occurred. Exemplary handler statements may be, for example, ‘catch’ 1222 ‘except,’ or ‘rescue.’ The catch block 1220 may then allow the user to examine the information in the error exception object, take corrective action, capture additional information about the error, alert a user to the existence of the exception, clean up the environment that was left by the failing code, or resume the execution of the code at the original location, using the information saved above to restore the code to its original state.
The foregoing and other features of the invention will be apparent from the following, more particular description of exemplary embodiments of the invention, as illustrated in the accompanying drawings wherein like reference numbers generally indicate identical, functionally similar, and/or structurally similar elements. The left most digits in the corresponding reference number indicate the drawing in which an element first appears.